<?php
/**
 * Виджет Feed_DoctypesMenuWidget рисует селектор типов документов для фильтра ленты.
 */

require_once 'MainPageWidget.php';
class Feed_DoctypesMenuWidget extends MainPageWidget
{
	public $title = 'Показать в ленте';

	public $doctype;
	public $rq_doctype = NULL;

	public function render() 
	{
		$db = $this->store->db;
		$this->rq_doctype = $this->parent->rq_doctype;

		$this->menu = $this->parent->model->getDocTypesForFeed();
		$filter_params = $this->parent->getDoctypeFilterParams();
		$check_all = true;
		foreach ($this->menu as $doctype=>&$item) {
			$item['url'] = $this->parent->hrefFilterByDoctype($doctype);
			$item['checked'] = in_array($doctype, $filter_params);
			if ($doctype !== 'all' && !$item['checked']) $check_all = false;
		}
		if ($check_all || $this->menu['all']['checked'] || empty($filter_params)) {
			foreach ($this->menu as $doctype=>&$item) {
				$item['checked'] = true;
			}
		} else {
				$this->menu['all']['checked'] = false;
		}

		return $this;
	}

	public function getActionFilter ()
	{
		return $this->parent->hrefFilterByDoctype('all');
	} // end of method getActionFilter

}

